<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    function minimumDeletions(nums) {
      let [max, min] = [Math.max(...nums), Math.min(...nums)]
      let [maxPos, minPos] = [nums.indexOf(max), nums.indexOf(min)]
      let len = nums.length
      let [left, right] = [Math.min(minPos, maxPos), Math.max(maxPos, minPos)]

      return Math.min(right + 1, len - left, 1 + left + len - right)

    };
    console.log(minimumDeletions([0, -4, 19, 1, 8, -2, -3, 5]));
  </script>
</body>

</html>